package com.lwt.bean;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用的返回类，不建议在控制层方法返回值返回对象，而是返回此通用类
 * @Author Li Weitong
 * @Date 2021/1/10 11:38
 */
public class JsonMsg {

    private int code; // 状态码

    private String msg; // 提示信息

    private Map<String,Object> map = new HashMap<String, Object>(); // 返回给浏览器的数据

    public JsonMsg add(String key,Object value){
        this.getMap().put(key, value);
        return this;
    }

    public static JsonMsg success(){
        JsonMsg jsonMsg = new JsonMsg();
        jsonMsg.setCode(100);
        jsonMsg.setMsg("处理成功");
        return jsonMsg;
    }
    public static JsonMsg fail(){
        JsonMsg jsonMsg = new JsonMsg();
        jsonMsg.setCode(200);
        jsonMsg.setMsg("处理失败");
        return jsonMsg;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

}
